<?php 
/*读者墙实现
作者:rakiy
时间:2011-11-20
说明:$num为条数
*/
function readers($num=10,$width=32,$height=32){
$period = time() - 2592000; // 時段: 30 天, 單位: 秒
$counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
->select('COUNT(author) AS cnt','author', 'url', 'mail')
->from('table.comments')
->where('created > ?', $period )
->where('status = ?', 'approved')
->where('type = ?', 'comment')
->where('authorId = ?', '0')
->group('author')
->order('cnt', Typecho_Db::SORT_DESC)
->limit($num)
);
$mostactive = '';
$avatar_path = Helper::options()->siteUrl . 'usr/avatar/';
foreach ($counts as $count) {
  $avatar = $avatar_path . md5(strtolower($count['mail'])) . '.jpg';
  $c_url = $count['url']; if ( !$c_url ) $c_url = Helper::options()->siteUrl;
  $mostactive .= "<li><a href='" . $c_url . "' title='" . $count['author'] . " (" . $count['cnt'] . "条评论)' target='_blank' rel='nofollow'><img src='" . $avatar . "' alt='' width='".$width."px' height='".$height."px'/></a></li>\n";
}
echo $mostactive;
}
function quote_change($str,$filter=0){
	$pat = '/\[quote(.*?)id=([0-9]*)\](.*?)\[\/quote\]/i';
	if ($filter){
		$str=preg_replace($pat , '' , $str);
	}else{
		$str=preg_replace($pat,'<a href="#comment-$2 ">@$3</a>', $str);	
	}
	return $str;
}
function tags($num=20){

$counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
->select('name','count')
->from('table.metas')
->where('type = ?', 'tag')
->order('count', Typecho_Db::SORT_DESC)
->limit($num)
);
$alltags='';
$tag_path = Helper::options()->siteUrl . 'tag/';
foreach ($counts as $count) {
	$alltags .= "<a style='color:rgb(".mt_rand(0,255).",".mt_rand(0,255).",".mt_rand(0,255).")' href='" . $tag_path . $count['name'] . "' title='有".$count['count']."篇文章使用".$count['name']."标签'>".$count['name']."</a>\n";
}
echo $alltags;
}
//右下角小图标
function icons(){
	$allicons = '';
	$tRss = (Helper::options()->tRss)?(Helper::options()->tRss):(Helper::options()->feedUrl);
	$tQQ  = (Helper::options()->tQQUrl)?(Helper::options()->tQQUrl):NULL;
	$tWeibo = (Helper::options()->WeiboUrl)?(Helper::options()->WeiboUrl):NULL;
	$allicons .='<li><a href="'.$tRss.'" class="icon1" target="_blank" title="订阅我的博客"></a></li>';
	if($tQQ){
	    $allicons .='<li><a href="'.$tQQ.'" class="icon2" target="_blank" title="订阅我的腾讯微博"></a></li>';
    }
	$allicons .='<li><a href="http://r.qq.com/cgi-bin/reader_switch?u='.Helper::options()->feedUrl.'" target="_blank" class="icon3" title="QQ邮箱订阅"></a></li>';				
	if($tWeibo){
		$allicons .='<li><a href="'.$tWeibo.'" target="_blank" class="icon4" title="订阅我的新浪微博"></a></li>';
	}
echo $allicons;
}
//控制面板
function themeConfig($form) {
//新浪微博
    $WeiboUrl = new Typecho_Widget_Helper_Form_Element_Text('WeiboUrl', NULL, NULL, _t('新浪微博'), _t('你的新浪微博地址，必须带 http://，不想显示请留空'));
    $form->addInput($WeiboUrl);
//腾讯微博	
    $tQQUrl = new Typecho_Widget_Helper_Form_Element_Text('tQQUrl', NULL,NULL , _t('腾讯微博'), _t('你的腾讯微博地址，必须带 http://，不想显示请留空'));
    $form->addInput($tQQUrl);	
//RSS地址	
    $tRss = new Typecho_Widget_Helper_Form_Element_Text('tRss', NULL,NULL , _t('订阅地址'), _t('如果'));
    $form->addInput($tRss);	
//备案号	
    $tbeian = new Typecho_Widget_Helper_Form_Element_Text('tbeian', NULL, NULL, _t('备案号'), _t('你的备案号，如没有请留空即可'));
    $form->addInput($tbeian);	
//网站统计	
	$tCount = new Typecho_Widget_Helper_Form_Element_Textarea('tCount', NULL, NULL, _t('统计代码'), _t('这里填写你的统计代码，不想显示请留空'));
    $form->addInput($tCount);		
//左下角显示
    $LeftCorner = new Typecho_Widget_Helper_Form_Element_Radio('LeftCorner', array('0' => _t('搜索'), '1'=> _t('名人名言')), '0', _t('左下角内容'),
    _t('皮肤左下角显示内容，如选择名人名言，则必须存在<a href="http://85s.googlecode.com/files/Famous.1.0.2.zip" target="_blank" title="点击这里下载">Famous</a>插件'));
    $form->addInput($LeftCorner);
//翻页类型
    $PageType = new Typecho_Widget_Helper_Form_Element_Radio('PageType', array('0' => _t('常规'), '1'=> _t('AJAX翻页')), '0', _t('翻页类型'),
    _t('如果你用了优化网址的插件，请使用常规翻页……否则会捕捉不到页码而无法读取……'));
    $form->addInput($PageType);
}
?>